package com.ftg.elvis.service;

import com.ftg.elvis.mapper.AdminBrandMapper;
import com.ftg.elvis.pojo.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminBrandService {

	@Autowired
	AdminBrandMapper adminBrandMapper;

	public List<Brand> showAll(int page, int limit, String bname) {
		page = (page - 1) * limit;
		bname = bname == null ? "" : bname;
		return adminBrandMapper.showAll(page, limit, bname);
	}

	public int getCount(String bname) {
		bname = bname == null ? "" : bname;
		return adminBrandMapper.getCount(bname);
	}

	@Transactional()
	public int delete(String bid) {
		adminBrandMapper.delete(bid);
		adminBrandMapper.deleteProduct(bid);
		return 1;
	}

	public int updateBrand(Brand brand) {
		return adminBrandMapper.updateBrand(brand);
	}
}
